#include <iostream>
#include <unordered_map>
#include <cmath>

// Dictionary that maps words to numbers
std::unordered_map<std::string, int> w2n = {
    {"zero", 0}, {"one", 1}, {"two", 2}, {"three", 3}, {"four", 4},
    {"five", 5}, {"six", 6}, {"seven", 7}, {"eight", 8}, {"nine", 9}
};

// Function that converts words to numbers
int words_to_num(const std::vector<std::string>& words) {
    try {
        // Use enumerate to get the index and the word
        // Sum the numbers multiplied by 10 to the power of the index
        int result = 0;
        for (int i = 0; i < words.size(); i++) {
            result += w2n.at(words[words.size() - 1 - i]) * std::pow(10, i);
        }
        return result;
    } catch (const std::out_of_range&) {
        return -1;
    }
}

// Function that finds the closest prime number to the given number
int closest_prime(int num) {
    if (is_prime(num)) {
        return num;
    }
    int shift = 1;
    while (true) {
        if (is_prime(num - shift)) {
            return num - shift;
        }
        if (is_prime(num + shift)) {
            return num + shift;
        }
        shift += 1;
    }
}

// Function that checks if a number is prime
bool is_prime(int n) {
    if (n <= 1) {
        return false;
    }
    if (n == 2) {
        return true;
    }
    if (n % 2 == 0) {
        return false;
    }
    for (int i = 3; i <= std::sqrt(n) + 1; i += 2) {
        if (n % i == 0) {
            return false;
        }
    }
    return true;
}

int main() {
    std::string input;
    std::getline(std::cin, input);
    std::vector<std::string> input_words;
    std::string word;
    std::istringstream iss(input);
    while (iss >> word) {
        input_words.push_back(word);
    }
    if (input_words.size() == 3) {
        int n = words_to_num(input_words);
        if (n != -1) {
            std::cout << closest_prime(n) << std::endl;
        } else {
            std::cout << "Wrong input" << std::endl;
        }
    } else {
        std::cout << "Wrong input" << std::endl;
    }
    return 0;
}

